package manage.model;

import m.common.model.DictionaryModel;
import m.common.model.FieldMeta;
import m.common.model.Model;
import m.common.model.TableMeta;
import m.common.model.config.ModelConfig;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;

import java.util.List;

@TableMeta(name="os_dictionary_type",description="字典类型表")
public class DictionaryType extends Model implements DictionaryModel {
	private static final long serialVersionUID = 1L;
	@FieldMeta(name="name",type=FieldType.STRING,length=50,notnull=true,description="类型名")
	private String name;
	@FieldMeta(name="type",type=FieldType.STRING,length=50,notnull=true,description="类型")
	private String type;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}

	@Override
	public String getDictValue() {
		return this.type;
	}

	@Override
	public String getDictName() {
		return this.getName();
	}

	@Override
	public String getDictParentOid() {
		return "";
	}

	@Override
	public String getDictStatus() {
		return "Y";
	}

	@Override
	public List<DictionaryType> getCacheList(String key) throws Exception {
		List<DictionaryType> list=ModelQueryList.getModelList(DictionaryType.class,"type","name");
		for(Class<? extends Model> clazz : ModelConfig.getTableList()){
			if(DictionaryModel.class.isAssignableFrom(clazz)){
				if(clazz.getName().startsWith("api.model.")){

				}else if(clazz.getName().startsWith("flow.model.")){

				}else if(clazz.getName().equals("manage.model.AdminGroup")){

				}else if(clazz.getName().equals("manage.model.AdminLogin")){

				}else if(clazz.getName().equals("manage.model.OrgGroupView")){

				}else{
					DictionaryType type=new DictionaryType();
					type.setType(clazz.getName());
					type.setName(ModelConfig.getTableMeta(clazz).description());
					list.add(type);
				}
			}
		}
		return list;
	}
}
